package com.godofball.todo.utils;


import com.godofball.todo.entity.Task;
import com.godofball.todo.entity.vo.WorkTaskVo;
import org.springframework.beans.BeanUtils;

import java.util.List;
import java.util.stream.Collectors;

public class BeanCopyUtils {
    private BeanCopyUtils() {
    }

    public static <T> T copyBean(Object source, Class<T> tClass) {
        T obj = null;
        try {
            obj = tClass.newInstance();
            BeanUtils.copyProperties(source, obj);
        } catch (Exception e) {
            throw new RuntimeException(e);
        }
        return obj;
    }

    public static <O,T> List<T> copyBeanList(List<O> source,Class<T> tClass){
        return source.stream().
                map(o -> copyBean(o, tClass)).
                collect(Collectors.toList());

    }


    public static void main(String[] args) {
        Task task = new Task();
        task.setId("32");
        WorkTaskVo workTaskVo = copyBean(task, WorkTaskVo.class);
        System.out.println(workTaskVo);
    }
}
